****************************************************************************************************
****************************************************************************************************
*Replication file for:
*The Importance of a Liberal Power's Attention to Democratic Elections Around the World
*Johannes Bubeck Ashrakat Elshehawy Nikolay Marinov Federico Nanni
****************************************************************************************************
****************************************************************************************************



clear
*please change to your own working directory
cd "/Data"

*use the nelda data that has been prepared in the very first step
use neldaprep


gen biasbin=(bias>.25) if bias!=.	



merge m:1 ccode year using usp_usc_attn

drop if _m==2

drop _m



merge m:1 ccode using coveredbydocs

replace attnbin=0 if year>=1945 & year<=2015 & attnbin==. & _m==3

drop if _m==2

drop _m



merge m:1 ccode using indepstates	

drop if _m==2

drop _m

edit ccode year countryname electionid biasbin attnbin uselein3 indepyear

*** IND YYR for graph

gen year_s="01/01/"+string(indepyear)

gen independence=date(year_s,"MDY")
format independence %td
drop year_s



*** COUNTRY - some cleaning

replace countryname=trim(countryname)

replace ccode=57 if ccode==670
replace countryname="DR Congo" if country=="Democratic Republic of Congo"
replace countryname="DR Vietnam" if country=="Democratic Republic of Vietnam"
replace countryname="S Vietnam" if country=="Republic of Vietnam"
replace countryname="Dominican R" if ccode==42
replace countryname="Trinidad and Tobago" if ccode==52
replace countryname="GDR" if ccode==265
replace countryname="Germany" if ccode==260
replace countryname="Yugo/Serbia" if ccode==345
replace countryname="Romania" if ccode==360
replace countryname="USSR/Russia" if ccode==365
replace countryname="CAR" if ccode==482
replace countryname="Congo (B)" if ccode==484
replace countryname="Congo (K)" if ccode==490
replace countryname="Gambia" if ccode==420
replace countryname="Tanzania" if ccode==510
replace countryname="Madagascar" if ccode==580
replace countryname="Cote d'Ivoire" if ccode==437
replace countryname="Zimbabwe" if ccode==552
replace countryname="S Yemen" if ccode==680
replace countryname="N Korea" if ccode==731
replace countryname="S Korea" if ccode==732
replace countryname="Myanmar" if ccode==775
replace countryname="Vietnam" if ccode==816
replace countryname="USA" if ccode==2
replace countryname="Trininad" if ccode==52
replace countryname="Grenada" if ccode==55
replace countryname="St. Lucia" if ccode==56
replace countryname="St. Vincent" if ccode==57
replace countryname="Antigua" if ccode==58 
replace countryname="St Kitts" if ccode==60 
replace countryname="UK" if ccode==200 
replace countryname="Chech R" if ccode==316  
replace countryname="Italy" if ccode==325
replace countryname="Bosnia" if ccode==346 
replace countryname="São Tomé" if ccode==403 
replace countryname="E Guinea" if ccode==411
replace countryname="Burkina" if ccode==439 
replace countryname="Zambia" if ccode==551 
replace countryname="S Africa" if ccode==560 
replace countryname="Swaziland" if ccode==572 
replace countryname="Micronesia" if ccode==987 
replace countryname="Samoa" if ccode==990 
replace countryname="Yemen" if ccode==678
replace countryname="Kyrgyzstan" if ccode==703
replace countryname="Djibouti" if ccode==522
replace countryname="Mongolia" if ccode==712	
replace countryname="Taiwan" if ccode==713
replace countryname="R Vietnam" if ccode==817	
replace countryname="Norway" if ccode==385
replace countryname="Morocco" if ccode==600	

compress countryname

*** Keep w comp/

keep if strpos(lower(nelda3),"y")>0 & strpos(lower(nelda4),"y")>0 & strpos(lower(nelda5),"y")>0

* ABkhasia and S Ossetia no docs

drop if ccode>=396 & ccode<=397

capture drop regcountry countrylab
capture label drop cty
gen regcountry=abbrev(countryname, 12)

replace regcountry=abbrev(countryname, 11)+"*" if ccode==396 | ccode==232 | ccode==58 | ccode==31 | ccode==53 | ccode==80 | ccode==987 | ccode==55 | ccode==970 | ccode==223 | ccode==212 | ccode==781 | ccode==983 | ccode==221 | ccode==971 | ccode==694 | ccode==56 | ccode==57 | ccode==60 | ccode==990 | ccode==331 | ccode==403 | ccode==591 | ccode==940 | ccode==397 | ccode==940 | ccode==115 | ccode==572 | ccode==972 | ccode==973 | ccode==935

encode regcountry, generate(countrylab) lab(cty)

su countrylab

* 	KEEP 1 round

drop if round~=1

***
*** --- GRAPHS ---
***
cd "/Figures"



*	very sm hol red cir
*** [independence] -> [no if] m(Oh) mc(red) mlw(medthin) msiz(vsmall) 

scatter countrylab independence if countrylab<=40 & independence>=-15 & year>=1945, m(Oh) mc(red) mlw(medthin) msiz(vsmall) ylabel(1(1)40, angle(0) valuelab labsize(small) noticks) legend(off) ytitle("") xtitle("")  yscale(rev) xlabel(-5475 "1945" 22265 "2021")

*	cross 
*** [date] -> if attnbin==1  m(X) mc(black)

scatter countrylab date if attnbin==1 & countrylab<=40 & year>=1945, m(X) mc(black) mlw(medthin) msiz(medium) ylabel(1(1)40, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("")  yscale(rev) xlabel(-5475 "1945" 22265 "2021")


*	circle hollow
*** [date] -> if biasbin==0 & uspreselein3==1  msymbol(Oh) mc(black) 

scatter countrylab date if biasbin==0 & uspreselein3==1 & countrylab<=40 & year>=1945, msymbol(Oh) mc(black) mlw(medthin) msiz(medium) ylabel(1(1)40, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("")  yscale(rev) xlabel(-5475 "1945" 22265 "2021")

*	circle filled 
*** [date] -> if biasbin==1 & uspreselein3==1  msymbol(O) mlcolor(gs5) mfcolor(gs12)

scatter countrylab date if biasbin==1 & uspreselein3==1 & countrylab<=40 & year>=1945, msymbol(O) mlcolor(gs5) mfcolor(gs12) mlw(medthin) msiz(medium) ylabel(1(1)40, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("")  yscale(rev) xlabel(-5475 "1945" 22265 "2021")

* 	square hollow
*** [date] -> if biasbin==0 & uspreselein3==0  m(Sh) mc(black) 

scatter countrylab date if biasbin==0 & uspreselein3==0 & countrylab<=40 & year>=1945, m(Sh) mc(black) mlw(medthin) msiz(medium) ylabel(1(1)40, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("")  yscale(rev) xlabel(-5475 "1945" 22265 "2021")

*	square filled
*** [date] -> if biasbin==1 & uspreselein3==0  m(S) mlcolor(gs5) mfcolor(gs12)

scatter countrylab date if biasbin==1 & uspreselein3==0 & countrylab<=40 & year>=1945, m(S) mlcolor(gs5) mfcolor(gs12) mlw(medthin) msiz(medium) ylabel(1(1)40, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("")  yscale(rev) xlabel(-5475 "1945" 22265 "2021")

*** Combining some - also need circles for close to US elections

set scheme s1mono


scatter countrylab independence if countrylab>0 & countrylab<=38 & independence>=-5475 & date>date("January 1 1946","MDY"), m(Oh) mc(red) mlw(medthin) msiz(vsmall) || ///
scatter countrylab date if attnbin==1 & countrylab>0 & countrylab<=38 & independence>=-5475 & date>date("January 1 1946","MDY"), m(X) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==0 & countrylab>0 & countrylab<=38 & date>date("January 1 1946","MDY"), m(Sh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==0 & countrylab>0 & countrylab<=38 & date>date("January 1 1946","MDY"), m(S) mlcolor(гс5) mfcolor(gs12%50) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==1 & countrylab>0 & countrylab<=38 & date>date("January 1 1946","MDY"), msymbol(Oh) mc(black) mlw(medthin) msiz(medium)  || ///
scatter countrylab date if biasbin==1 & uspreselein3==1 & countrylab>0 & countrylab<=38 & date>date("January 1 1946","MDY"), msymbol(O) mlcolor(gs5) mfcolor(gs12%50) mlw(medthin) msiz(medium) ylabel(1(1)38, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("") yscale(rev) xlabel(-5478(5479)21900, format(%tdCY)) aspectratio(.77)saving(figure_c_1)


graph export figure_c_1.tif
graph export figure_c_1.pdf




scatter countrylab independence if countrylab>38 & countrylab<=76 & independence>=-5475 & date>date("January 1 1946","MDY"), m(Oh) mc(red) mlw(medthin) msiz(vsmall) || ///
scatter countrylab date if attnbin==1 & countrylab>38 & countrylab<=76 & date>date("January 1 1946","MDY"), m(X) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==0 & countrylab>38 & countrylab<=76 & date>date("January 1 1946","MDY"), m(Sh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==0 & countrylab>38 & countrylab<=76 & date>date("January 1 1946","MDY"), m(S) mlcolor(гс5) mfcolor(gs12%50) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==1 & countrylab>38 & countrylab<=76 & date>date("January 1 1946","MDY"), msymbol(Oh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==1 & countrylab>38 & countrylab<=76 & date>date("January 1 1946","MDY"), msymbol(O) mlcolor(gs5) mfcolor(gs12%50) mlw(medthin) msiz(medium) ylabel(39(1)76, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("") yscale(rev) xlabel(-5478(5479)21900, format(%tdCY)) aspectratio(.77) saving(figure_c_2, replace)

graph export figure_c_2.tif, replace
graph export figure_c_2.pdf, replace




scatter countrylab independence if countrylab>77 & countrylab<=114 & independence>=-5475 & date>date("January 1 1946","MDY"), m(Oh) mc(red) mlw(medthin) msiz(vsmall) || ///
scatter countrylab date if attnbin==1 & countrylab>77 & countrylab<=114 & date>date("January 1 1946","MDY"), m(X) mc(black) mlw(medthin) msiz(medium)  || ///
scatter countrylab date if biasbin==0 & uspreselein3==0 & countrylab>77 & countrylab<=114 & date>date("January 1 1946","MDY"), m(Sh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==0 & countrylab>77 & countrylab<=114 & date>date("January 1 1946","MDY"), m(S) mlcolor(гс5) mfcolor(gs12%50) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==1 & countrylab>77 & countrylab<=114 & date>date("January 1 1946","MDY"), msymbol(Oh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==1 & countrylab>77 & countrylab<=114 & date>date("January 1 1946","MDY"), msymbol(O) mlcolor(gs5) mfcolor(gs12%50) mlw(medthin) msiz(medium) ylabel(77(1)114, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("") xlabel(-5478(5479)21900, format(%tdCY)) yscale(rev) saving(figure_c_3, replace)

graph export figure_c_3.tif, replace
graph export figure_c_3.pdf, replace



scatter countrylab independence if countrylab>114 & countrylab<=152 & independence>=-5475 & date>date("January 1 1946","MDY"), m(Oh) mc(red) mlw(medthin) msiz(vsmall) || ///
scatter countrylab date if attnbin==1 & countrylab>114 & countrylab<=152 & date>date("January 1 1946","MDY"), m(X) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==0 & countrylab>114 & countrylab<=152 & date>date("January 1 1946","MDY"), m(Sh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==0 & countrylab>114 & countrylab<=152 & date>date("January 1 1946","MDY"), m(S) mlcolor(гс5) mfcolor(gs12%50) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==1 & countrylab>114 & countrylab<=152 & date>date("January 1 1946","MDY"), msymbol(Oh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==1 & countrylab>114 & countrylab<=152 & date>date("January 1 1946","MDY"), msymbol(O) mlcolor(gs5) mfcolor(gs12%50) mlw(medthin) msiz(medium) ylabel(115(1)152, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("")  xlabel(-5478(5479)21900, format(%tdCY)) yscale(rev) saving(figure_c_4, replace)

graph export figure_c_4.tif, replace
graph export figure_c_4.pdf, replace



scatter countrylab independence if countrylab>152 & countrylab<=190 & independence>=-5475 & date>date("January 1 1946","MDY"), m(Oh) mc(red) mlw(medthin) msiz(vsmall)  || ///
scatter countrylab date if attnbin==1 & countrylab>152 & countrylab<=190 & date>date("January 1 1946","MDY"), m(X) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==0 & countrylab>152 & countrylab<=190 & date>date("January 1 1946","MDY"), m(Sh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==0 & countrylab>152 & countrylab<=190 & date>date("January 1 1946","MDY"), m(S) mlcolor(гс5) mfcolor(gs12%50) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==0 & uspreselein3==1 & countrylab>152 & countrylab<=190 & date>date("January 1 1946","MDY"), msymbol(Oh) mc(black) mlw(medthin) msiz(medium) || ///
scatter countrylab date if biasbin==1 & uspreselein3==1 & countrylab>152 & countrylab<=190 & date>date("January 1 1946","MDY"), msymbol(O) mlcolor(gs5) mfcolor(gs12%50) mlw(medthin) msiz(medium) ylabel(153(1)190, angle(0) valuelab labsize(vsmall) noticks) legend(off) ytitle("") xtitle("")  yscale(rev) xlabel(-5478(5479)21900, format(%tdCY)) saving(figure_c_5, replace)

graph export figure_c_5.tif, replace
graph export figure_c_5.pdf, replace
